package merchant

import (
	"context"
	"fmt"
	"go-zero-mult/service/rpc/merchant/merchant"

	"go-zero-mult/service/api/internal/svc"
	"go-zero-mult/service/api/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
)

type MerchantLoginLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMerchantLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) MerchantLoginLogic {
	return MerchantLoginLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MerchantLoginLogic) MerchantLogin(req types.LoginReq) (*types.LoginResp, error) {
	// todo: add your logic here and delete this line
	merchantInfo, err := l.svcCtx.MerchantRpc.MerchantLogin(l.ctx,&merchant.LoginReq{
		Username: req.Username,
		Password: req.Password,
	})

	fmt.Println(merchantInfo)
	if err != nil {
		return nil, err
	}
	return &types.LoginResp{
		Username: fmt.Sprintf("用户名称:%s,性别:%d登录成功\n",merchantInfo.Username,merchantInfo.Gender),
	}, nil
	//return &types.LoginResp{}, nil
}
